﻿// SDMX Artefact Standalone Editor (SAE). An SDMX 2.0 Editor.
//    Copyright (C) 2009-2011  Philippe Prati
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//    Contact: ph.prati@bluewin.ch or sdmx@nextsoft.ch 
//    Download:  http://www.sdmx.ch
//
using System;
using System.Xml;
using System.Windows.Forms;

namespace PluginInterface
{
    /// <summary>
    /// Contract for the implementation of a minimal set of methods by the plugins.
    /// These methods are used by the main (incorporating) application to find and
    /// recognize the plugins. This minimal set of method is achieved by making this
    /// interface, which declares the methods, that are to be implemented by the plugins.
    /// </summary>
    public interface IPlugin
    {
        /// <summary> 
        /// An event generator to notify a SDMX-ML document is to be consumed by the main application.
        /// </summary>
        event PluginEvent PluginEventExposed;

        /// <summary>
        /// this method will be called when the plugin is activated if 'RequiresInit' is set to true.
        /// </summary>
        /// <param name="xDoc">null or an XML SDMX-ML document representing the artefact selected
        /// in the main application.
        /// </param> <param name="obExtend">Reserved</param>
        void Init(XmlDocument xDoc, object obExtend);

        /// <summary>
        ///  VisualComponent allows the main application to retrieve the Visual control of the plugin
        ///   and to incorporate it in the reserved area or as a dislog box.
        /// </summary>
        /// <returns>the user control implementing this interface</returns>
        UserControl VisualComponent();

        // If true, the Init method of the plugin is called when activated.
        // if false, the Init method is not called.
        bool RequiresInit { get; }

    }


    //The event architecture offers a mechanism for an event generator to notify an event
    // consumer that something happened. The event generator does not need to know anything
    // about the consumer. Instead it publishes a method definition in the form of a delegate,
    // plus an event handle. When the event happens, the generator will call the unknown event
    // handling method of the consumer through the event handle.
    public class PluginEventArgs : EventArgs
    {
        public XmlDocument DocSdmxMl { get; set; }

        public PluginEventArgs(XmlDocument xDoc)
        {
            DocSdmxMl = xDoc;
        }
    }

    /// <summary> Publishes the method definition in the form of a delegate </summary>
    /// <param name="sender"></param>/ <param name="e">PluginEventArgs instance</param>
    public delegate void PluginEvent(object sender, PluginEventArgs e);


}
